package ncrnadb.cli;

import java.util.Collection;
import java.util.TreeSet;

import com.tinkerpop.blueprints.Vertex;

import ncrnadb.core.EntityType;
import ncrnadb.core.ORDB;
import ncrnadb.core.RID;

public class List {

	
	public static void usage(){
		System.out.println("Usage: cmd [ncrna, rna, gene, disease, others, all]");
	}
	
	public static void main(String[] args){
		Collection<EntityType> eTypes = new TreeSet<EntityType>();
		
		try{
			
			for(int i=0; i<args.length; i++){
				EntityType etype = EntityType.getByType(args[i].toUpperCase());
				if(etype == null){
					if(args[i].compareTo("others") == 0)
						etype = EntityType.OTHERS;
					else if(args[i].compareTo("all") == 0){
						eTypes.add(EntityType.NCRNA);
						eTypes.add(EntityType.RNA);
						eTypes.add(EntityType.GENE);
						eTypes.add(EntityType.DISEASE);
						eTypes.add(EntityType.OTHERS);
					}
					else
						throw new Exception();
				}
				if(etype!=null)
				eTypes.add(etype);
			}
			
		}catch(Exception e){
			usage();
			System.exit(1);
		}
		
		
		try{
			
			ORDB ordb = new ORDB();
			ordb.open();
			
			for(EntityType eType : eTypes){
				Iterable<Vertex> ents = ordb.getEntitiesOfType(eType);
				
				for(Vertex v : ents){
					Collection<RID> rids = ordb.getRIDs(v);
					
					System.out.print(eType.type+"\t"+v.getId().toString()+"\t");
					for(RID rid : rids){
						System.out.print(rid.toString());
					}
					System.out.println();
				}
			}
			
			
			ordb.close();
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e);
		}
	}
}
